package com.jysz.certificate.persistence.model.cs;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.jysz.certificate.persistence.enums.PostType;
import com.jysz.certificate.persistence.enums.cs.CheckStockStatus;
import com.jysz.certificate.persistence.model.system.Shop;
import com.jysz.certificate.persistence.model.system.User;
import com.jysz.webcore.ssh.entity.AbstractBaseEntity;

/**
 * 盘库
 * @author xuxiaolong
 */
@Entity
@Table(name="cs_checkstock_")
@org.hibernate.annotations.Entity
public class CheckStock extends AbstractBaseEntity<Long> {

	private static final long serialVersionUID = 7464539572818226926L;
	
	/** 发起人*/
	private User sponsor;
	
	/** 店铺*/
	private Shop shop;
	
	/** 驻店员*/
	private User shopUser;
	
	/** 区域经理*/
	private User areaManager;
	
	/** 是否现场盘库*/
	private Boolean live;
	
	/** 来源*/
	private PostType source;

	/** 状态*/
	private CheckStockStatus status;
	
	/** 完成时间*/
	private Date finishDate;
	
	/** 结果备注*/
	private String resultRemark;
	
	/** 备注*/
	private String remark;
	
	/** 是否成功*/
	private Boolean success;
	
	/** 包含的合格证*/
	private List<CheckStockOption> options;

	@ManyToOne(fetch = FetchType.LAZY,cascade=CascadeType.REFRESH)  
	@JoinColumn(name = "_sponsor_user_id",insertable=true, updatable=true,columnDefinition="bigint(20)")
	public User getSponsor() {
		return sponsor;
	}

	public void setSponsor(User sponsor) {
		this.sponsor = sponsor;
	}

	@ManyToOne(fetch = FetchType.LAZY,cascade=CascadeType.REFRESH)  
	@JoinColumn(name = "_shop_id",insertable=true, updatable=true,columnDefinition="bigint(20)")
	public Shop getShop() {
		return shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	@ManyToOne(fetch = FetchType.LAZY,cascade=CascadeType.REFRESH)  
	@JoinColumn(name = "_shop_user_id",insertable=true, updatable=true,columnDefinition="bigint(20)")
	public User getShopUser() {
		return shopUser;
	}

	public void setShopUser(User shopUser) {
		this.shopUser = shopUser;
	}

	@ManyToOne(fetch = FetchType.LAZY,cascade=CascadeType.REFRESH)  
	@JoinColumn(name = "_area_user_id",insertable=true, updatable=true,columnDefinition="bigint(20)")
	public User getAreaManager() {
		return areaManager;
	}

	public void setAreaManager(User areaManager) {
		this.areaManager = areaManager;
	}

	@Column(name= "_live",nullable=false,columnDefinition="int(11)")
	public Boolean getLive() {
		return live;
	}

	public void setLive(Boolean live) {
		this.live = live;
	}

	@Column(name= "_source",nullable=false,columnDefinition="int(11)")
	public PostType getSource() {
		return source;
	}

	public void setSource(PostType source) {
		this.source = source;
	}

	@Column(name= "_status",nullable=false,columnDefinition="int(11)")
	public CheckStockStatus getStatus() {
		return status;
	}

	public void setStatus(CheckStockStatus status) {
		this.status = status;
	}

	@OneToMany(targetEntity = CheckStockOption.class, cascade = { CascadeType.ALL }, mappedBy = "checkStock")  
	@Fetch(FetchMode.SUBSELECT)
	public List<CheckStockOption> getOptions() {
		return options;
	}

	public void setOptions(List<CheckStockOption> options) {
		this.options = options;
	}

	@Column(name= "_submit_date",nullable=true)
	public Date getFinishDate() {
		return finishDate;
	}

	public void setFinishDate(Date finishDate) {
		this.finishDate = finishDate;
	}

	@Column(name= "_remark",nullable=true,columnDefinition="varchae(255)")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "_success", nullable = true,columnDefinition="bit(1)")
	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	@Column(name= "_result_remark",nullable=true,columnDefinition="varchae(255)")
	public String getResultRemark() {
		return resultRemark;
	}

	public void setResultRemark(String resultRemark) {
		this.resultRemark = resultRemark;
	}
	
}
